from django.http import HttpResponseRedirect
from django.urls import reverse

from common.models import User


def is_login(func):

    def check(request, *args, **kwargs):
        if 'user_id' in request.session:
            request.user = User.objects.filter(pk=request.session['user_id']).first()
            return func(request, *args, **kwargs)
        return HttpResponseRedirect(reverse('user:login'))

    return check
